package com.baofu.paycore.service.factory.impl;

import com.baofu.paycore.common.utils.PayNoGenerateUtil;
import com.baofu.paycore.manager.model.withdraw.WithdrawBO;
import com.baofu.paycore.service.facade.enums.ServiceCodeEnum;
import com.baofu.paycore.service.facade.model.withdraw.UnfreezeWithdrawDTO;
import com.baofu.paycore.service.processor.withdraw.UnfreezeWithdrawBankProcessor;
import com.baofu.paycore.service.processor.withdraw.UnfreezeWithdrawFundProcessor;
import com.baofu.paycore.service.processor.withdraw.UnfreezeWithdrawProcessor;
import com.system.commons.sequence.redis.SequenceFacade;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * <p>
 * </p>
 * User:ames wang  Date: 2017/5/11
 */
@Slf4j
@Component
public class UnfreezeWithdrawFactoryImpl {

    /**
     * 主单处理器
     */
    @Resource(name = "unfreezeWithdrawProcessor")
    private UnfreezeWithdrawProcessor commonProcessor;

    /**
     * 资金单处理器
     */
    @Resource(name = "unfreezeWithdrawFundProcessor")
    private UnfreezeWithdrawFundProcessor fundProcessor;

    /**
     * 银行单
     */
    @Resource(name = "unfreezeWithdrawBankProcessor")
    private UnfreezeWithdrawBankProcessor bankProcessor;


    /**
     * 资金单No
     */
    @Autowired
    private SequenceFacade sequenceFacade;

    /**
     * 组装提现模型
     *
     * @param baseDTO   请求对象
     * @return          提现模型
     */
    public WithdrawBO build(UnfreezeWithdrawDTO baseDTO) {
        WithdrawBO withdrawBO = new WithdrawBO();
        //支付单号构建
        withdrawBO.setPayNo(PayNoGenerateUtil.payNoGenerate(sequenceFacade, baseDTO.getServiceCode()));
        commonProcessor.process(withdrawBO,baseDTO);
        fundProcessor.process(withdrawBO,baseDTO);
        if(ServiceCodeEnum.ISSUE_WITHDRAW.getCode().equals(baseDTO.getServiceCode())){
            bankProcessor.process(withdrawBO,baseDTO);
        }
        return withdrawBO;
    }
}
